<template>
  <el-container class="main_container">
        <el-header>
            <div>
                <img src="@/assets/heima.png" alt="">
                <span>后台管理系统</span>
            </div>
            <el-button type="info" @click="loginOut">退出</el-button>
        </el-header>
        <el-container>
            <el-aside :width="isCollapse?'64px':'200px'">
                <div class="toggle_buttom" @click="toggleBotton">|||</div>
                <el-menu
                    background-color="#333744"
                    text-color="#fff"
                    active-text-color="#409bff"
                    unique-opened
                    :collapse-transition="false"
                    :collapse="isCollapse"
                    router
                    :default-active='menuActive'
                    >
                    <!-- 一级菜单 -->
                    <el-submenu :index="item.id+''" v-for="(item,index) in menuList" :key="index">
                        <template slot="title">
                            <i :class="iconsObject[item.id]"></i>
                            <span>{{item.authName}}</span>
                        </template>
                        <!-- 二级菜单 -->
                        <el-menu-item :index="'/'+v.path" v-for="(v,i) in item.children" :key="i" @click="savePath('/'+v.path)">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>{{v.authName}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script lang="ts">
  import {apiAddress} from "@/utils/apiAddress";
    import {Component,Vue, Provide} from "vue-property-decorator";
    @Component({})
    export default class Home extends Vue{
        menuActive:String | null="";
        menuList:[]=[];
        isCollapse:boolean=false;
        iconsObject:{
            '125':String,
            '103':String,
            '101':String,
            '102':String,
            '145':String,
            '110':String,
        }={
            '125':'el-icon-user-solid',
            '103':'el-icon-s-management',
            '101':'el-icon-s-shop',
            '102':'el-icon-s-order',
            '145':'el-icon-s-data',
            '110':'el-icon-s-data',
        }
        created(){
            this.menus();
            this.menuActive=window.sessionStorage.getItem('menuActive')
        }
        savePath(path:string){
            window.sessionStorage.setItem("menuActive",path);
            this.menuActive=path
        }
        toggleBotton():void{
            this.isCollapse=!this.isCollapse
        }
        async menus(){
            const res=await apiAddress.menus2({});
            if(res.meta.status!=200) return this.$message.error(res.meta.msg);
            this.menuList=res.data
        }
        loginOut():void {
            window.sessionStorage.clear();
            this.$router.push('/login')
        }
    }
</script>

<style scoped lang="scss">
.main_container{
    height: 100%;
}
.el-header{
    background-color: #373d41;
    display: flex;
    display: -webkit-flex;
    justify-content: space-between;
    align-items:center;
    span{
        color: #fff;
        font-size: 20px;
        margin-left: 15px;
    }
    div{
        display: flex;
        display: -webkit-flex;
        align-items:center;
    }
}
.el-aside{
    background-color: #333744;
}
.el-menu{
    border: 0;
}
.toggle_buttom{
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    background-color: #4a5064;
    text-align: center;
    cursor: pointer;
    letter-spacing: 0.2em;
}
</style>
